In [1]:
import graphlab
In [2]:
# Limit number of worker processes. This preserves system memory, which prevents hosted notebooks from crashing.
graphlab.set_runtime_config('GRAPHLAB_DEFAULT_NUM_PYLAMBDA_WORKERS', 4)
In [3]:
image_train = graphlab.SFrame('image_train_data/')
In [4]:
image_test = graphlab.SFrame('image_test_data/')
In [5]:
image_train.head()
Out[5]:
In [6]:
knn_model = graphlab.nearest_neighbors.create(image_train, features=['deep_features'], label='id')
In [7]:
cat = image_train[18:19]
In [8]:
graphlab.canvas.set_target('ipynb')
In [9]:
cat['image'].show()
In [10]:
knn_model.query(cat)
Out[10]:
In [12]:
def get_images_from_ids(query_result):
return image_train.filter_by(query_result['reference_label'], 'id')
In [13]:
cat_neighbours = get_images_from_ids(knn_model.query(cat))
In [14]:
cat_neighbours['image'].show()
In [15]:
car = image_train[8:9]
In [16]:
car['image'].show()
In [17]:
get_images_from_ids(knn_model.query(car))['image'].show()
In [18]:
show_neighbours = lambda i : get_images_from_ids(knn_model.query(image_train[i:i+1]))['image'].show()
In [19]:
show_neighbours(26)
In [20]:
show_neighbours(8)
In [21]:
show_neighbours(1222)
In [22]:
show_neighbours(2000)
In [23]:
show_neighbours(100)
In [ ]: